﻿using System;
using System.ComponentModel.Composition;

using Warehouse.Service.Data;
using Warehouse.Silverlight.Core.Infrastructure.Events;
using Warehouse.Silverlight.Core.Infrastructure.Models;

namespace Warehouse.Silverlight.Modules.Main.Models
{
    [Export(typeof(IProductListModel))]
    public class ProductListModel : Model<ProductionContext>, IProductListModel
    {

        protected override void Initialize()
        {
            this.Context = ProductionContext.Instance;
        }

        public event EventHandler<EntityResultsArgs<Product>> GetProductsByCodeOrNameComplete;
        public void GetProductsByCodeOrNameAsync(string text)
        {
            PerformEntityQuery<Product>(Context.GetProductsByCodeOrNameQuery(text), GetProductsByCodeOrNameComplete);
        }

        public event EventHandler<EntityResultsArgs<Product>> GetProductsComplete;
        public void GetProductsAsync()
        {
            PerformEntityQuery<Product>(Context.GetProductsQuery(), GetProductsComplete);
        }
    }
}
